package com.mszlu.blog.controller;

import com.mszlu.blog.service.ArticleService;
import com.mszlu.blog.vo.Result;
import com.mszlu.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//使用json交互
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    ArticleService articleService;
    /**
     * 首页文章列表
     * @param pageParams
     * @return
     */
    @PostMapping
    public Result listArticles(@RequestBody PageParams pageParams){ //获取封装请求体中的json对象 vo：value object
        return articleService.listArticle(pageParams);
    }

    @PostMapping("hot")
    public Result hotArticle(){
        int limit =2;
        return  articleService.hotArticle(limit);
    }
    @PostMapping("new")
    public Result newArticle(){
        int limit =3;
        return  articleService.newArticle(limit);
    }

    @PostMapping("listArchives")
    public Result listArchives(){
        return  articleService.listArchives();
    }


}
